variable "gcp_project_id" {
  description = "The project to deploy the cluster in"
  type        = string
}

variable "gcp_region" {
  type = string
}

variable "gcp_zone" {
  description = "All GCP resources will be launched in this Zone."
  type        = string
}

variable "server_cluster_size" {
  type = number
}

variable "server_machine_type" {
  type = string
}

variable "client_cluster_size" {
  type    = number
  default = 0
}

variable "client_cluster_size_max" {
  type    = number
  default = 0
}

variable "client_machine_type" {
  type = string
}

variable "api_cluster_size" {
  type = number
}

variable "api_machine_type" {
  type = string
}

variable "api_node_pool" {
  type    = string
  default = "api"
}

variable "api_use_nat" {
  type        = bool
  description = "Whether API nodes should use NAT with dedicated external IPs."
  default     = false
}

variable "api_nat_ips" {
  type        = list(string)
  description = "List of names for static IP addresses to use for NAT. If empty and api_use_nat is true, IPs will be created automatically."
  default     = []
}

variable "api_resources_cpu_count" {
  type    = number
  default = 2
}

variable "api_resources_memory_mb" {
  type    = number
  default = 2048
}

variable "build_cluster_size" {
  type = number
}

variable "build_machine_type" {
  type = string
}

variable "build_node_pool" {
  type    = string
  default = "build"
}

variable "build_cluster_root_disk_size_gb" {
  type        = number
  description = "The size of the root disk for the build machines in GB"
  default     = 200
}

variable "build_cluster_cache_disk_size_gb" {
  type        = number
  description = "The size of the cache disk for the build machines in GB"
  default     = 200
}

variable "build_cluster_cache_disk_type" {
  description = "The GCE cache disk type for the build machines."
  type        = string
  default     = "pd-ssd"
}

variable "clickhouse_cluster_size" {
  type = number
}

variable "clickhouse_machine_type" {
  type = string
}

variable "clickhouse_database_name" {
  description = "The name of the ClickHouse database to create."
  type        = string
  default     = "default"
}

variable "clickhouse_job_constraint_prefix" {
  description = "The prefix to use for the job constraint of the instance in the metadata."
  type        = string
  default     = "clickhouse"
}

variable "clickhouse_node_pool" {
  description = "The name of the Nomad pool."
  type        = string
  default     = "clickhouse"
}

variable "clickhouse_server_service_port" {
  type = object({
    name = string
    port = number
  })
  default = {
    name = "clickhouse"
    port = 9000
  }
}

variable "clickhouse_health_port" {
  type = object({
    name = string
    port = number
    path = string
  })
  default = {
    name = "clickhouse-health"
    port = 8123
    path = "/health"
  }
}

variable "client_proxy_count" {
  type    = number
  default = 1
}

variable "ingress_count" {
  type    = number
  default = 1
}

variable "client_proxy_resources_memory_mb" {
  type    = number
  default = 1024
}

variable "client_proxy_resources_cpu_count" {
  type    = number
  default = 1
}

variable "client_proxy_update_max_parallel" {
  type        = number
  description = "The number of client proxies to update in parallel during a rolling update."
  default     = 1
}

variable "edge_api_port" {
  type = object({
    name = string
    port = number
    path = string
  })
  default = {
    name = "edge-api"
    port = 3001
    path = "/health/traffic"
  }
}

variable "edge_proxy_port" {
  type = object({
    name = string
    port = number
  })
  default = {
    name = "session"
    port = 3002
  }
}

variable "loki_cluster_size" {
  type    = number
  default = 0
}

variable "loki_machine_type" {
  type    = string
  default = "e2-standard-4"
}

variable "loki_node_pool" {
  type    = string
  default = "loki"
}

variable "api_port" {
  type = object({
    name        = string
    port        = number
    health_path = string
  })
  default = {
    name        = "api"
    port        = 50001
    health_path = "/health"
  }
}

variable "ingress_port" {
  type = object({
    name        = string
    port        = number
    health_path = string
  })
  default = {
    name        = "ingress"
    port        = 8800
    health_path = "/ping"
  }
}

variable "docker_reverse_proxy_port" {
  type = object({
    name        = string
    port        = number
    health_path = string
  })
  default = {
    name        = "docker-reverse-proxy"
    port        = 5000
    health_path = "/health"
  }
}

variable "redis_port" {
  type = object({
    name = string
    port = number
  })
  default = {
    name = "redis"
    port = 6379
  }
}

variable "nomad_port" {
  type    = number
  default = 4646
}

variable "allow_sandbox_internet" {
  type    = bool
  default = true
}

variable "client_cluster_cache_disk_size_gb" {
  type        = number
  description = "The size of the cache disk for the orchestrator machines in GB"
  default     = 500
}

variable "client_cluster_cache_disk_type" {
  description = "The GCE cache disk type for the client machines."
  type        = string
  default     = "pd-ssd"
}

variable "orchestrator_node_pool" {
  type    = string
  default = "default"
}

variable "orchestrator_port" {
  type    = number
  default = 5008
}

variable "orchestrator_proxy_port" {
  type    = number
  default = 5007
}

variable "template_manager_port" {
  type    = number
  default = 5008 // we want to use the same port for both because of edge api
}

variable "envd_timeout" {
  type    = string
  default = "40s"
}

variable "environment" {
  type    = string
  default = "prod"
}

variable "otel_collector_resources_memory_mb" {
  type    = number
  default = 1024
}

variable "otel_collector_resources_cpu_count" {
  type    = number
  default = 0.5
}

variable "clickhouse_resources_memory_mb" {
  type    = number
  default = 8192
}

variable "clickhouse_resources_cpu_count" {
  type    = number
  default = 4
}

variable "otel_tracing_print" {
  description = "Whether to print OTEL traces to stdout"
  type        = bool
  default     = false
}

variable "domain_name" {
  type        = string
  description = "The domain name where e2b will run"
}

variable "additional_domains" {
  type        = string
  description = "Additional domains which can be used to access the e2b cluster, separated by commas"
  default     = ""
}

variable "additional_api_services_json" {
  type        = string
  description = <<EOT
Additional path rules to add to the API path matcher.
Format: json string of an array of objects with 'path' and 'service' keys.
Example:
[
  {
    "paths": ["/api/v1"],
    "service_id": "projects/e2b/global/backendServices/example",
    "api_node_group_port_name": "example-port",
    "api_node_group_port": 8080
  }
]
EOT
  default     = ""
}

variable "prefix" {
  type        = string
  description = "The prefix to use for all resources in this module"
  default     = "e2b-"
}

variable "labels" {
  description = "The labels to attach to resources created by this module"
  type        = map(string)
  default = {
    "app"       = "e2b"
    "terraform" = "true"
  }
}

variable "loki_resources_memory_mb" {
  type    = number
  default = 2048
}

variable "loki_resources_cpu_count" {
  type    = number
  default = 1
}

variable "loki_service_port" {
  type = object({
    name = string
    port = number
  })
  default = {
    name = "loki"
    port = 3100
  }
}

variable "template_bucket_location" {
  type        = string
  description = "The location of the FC template bucket"
}

variable "template_bucket_name" {
  type        = string
  description = "The name of the FC template bucket"
  default     = ""
}

variable "redis_managed" {
  default = false
  type    = bool
}

variable "filestore_cache_enabled" {
  type        = bool
  description = "Set to true to enable Filestore cache. Can be set via TF_VAR_use_filestore_cache or USE_FILESTORE_CACHE env var."
  default     = false
}

variable "filestore_cache_tier" {
  type        = string
  description = "The tier of the Filestore cache"
  default     = "BASIC_HDD"
}

variable "filestore_cache_capacity_gb" {
  type        = number
  description = "The capacity of the Filestore cache in GB"
  default     = 0
}

variable "filestore_cache_cleanup_disk_usage_target" {
  type        = number
  description = "The max disk usage target of the Filestore"
  default     = 90
}

variable "filestore_cache_cleanup_dry_run" {
  type    = bool
  default = false
}

variable "filestore_cache_cleanup_files_per_loop" {
  type    = number
  default = 10000
}

variable "filestore_cache_cleanup_deletions_per_loop" {
  type    = number
  default = 900
}

variable "min_cpu_platform" {
  type    = string
  default = "Intel Skylake"
}

variable "build_base_hugepages_percentage" {
  description = "The percentage of memory to use for preallocated hugepages."
  type        = number
  default     = 60
}

variable "orchestrator_base_hugepages_percentage" {
  description = "The percentage of memory to use for preallocated hugepages."
  type        = number
  default     = 80
}

variable "remote_repository_enabled" {
  type        = bool
  description = "Set to true to enable remote repository cache. Can be set via TF_VAR_remote_repository_enabled or REMOTE_REPOSITORY_ENABLED env var."
  default     = false
}
